package cn.vc.basicmodule.util;

import cn.vc.basicmodule.entity.Result;
import cn.vc.basicmodule.util.Logging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ResultBuilder {
    @Autowired
    private Logging logging;

    public<T> Result<T> returnMsg(int code, T data, String msg) {
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setMsg(msg);
        if (code == 0) {
            result.setCode(403);
            logging.warn(result.toString());
        } else {
            result.setCode(code);
            logging.info(result.toString());
        }
        return result;
    }
}
